package com.h.autoconfigure;

import com.h.Strategy.BootstrapStrategy;
import com.h.api.TransferProtocol;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：Hukaiwen
 * @description ：配置连接集合
 * @date ：2022/1/24 10:04
 */
@ConfigurationProperties(prefix = "netty.config")
public class NettyConfigProperties {

    private final List<Configuration> configurations;

    public NettyConfigProperties() {
        configurations = new ArrayList<>();
    }

    public List<Configuration> getConfigurations() {
        return configurations;
    }

    public static class Configuration {
        private URI localAddress;
        private URI remoteAddress;
        private String name;
        private TransferProtocol protocol;
        private URI multicastAddress;
        private URI broadcastAddress;
        private boolean available;
        private boolean autoStart;
        private Integer reconnect;
        private boolean retry;
        private Class<? extends BootstrapStrategy<?, ?>> bootstrapStrategy;

        public Configuration() throws URISyntaxException {
            this.localAddress = new URI("127.0.0.1");
            this.available = true;
            this.autoStart = true;
            this.reconnect = 5;
            this.retry = true;
        }

        public URI getLocalAddress() {
            return localAddress;
        }

        public void setLocalAddress(URI localAddress) {
            this.localAddress = localAddress;
        }

        public URI getRemoteAddress() {
            return remoteAddress;
        }

        public void setRemoteAddress(URI remoteAddress) {
            this.remoteAddress = remoteAddress;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public TransferProtocol getProtocol() {
            return protocol;
        }

        public void setProtocol(TransferProtocol protocol) {
            this.protocol = protocol;
        }

        public URI getMulticastAddress() {
            return multicastAddress;
        }

        public void setMulticastAddress(URI multicastAddress) {
            this.multicastAddress = multicastAddress;
        }

        public URI getBroadcastAddress() {
            return broadcastAddress;
        }

        public void setBroadcastAddress(URI broadcastAddress) {
            this.broadcastAddress = broadcastAddress;
        }

        public boolean isAvailable() {
            return available;
        }

        public void setAvailable(boolean available) {
            this.available = available;
        }

        public boolean isAutoStart() {
            return autoStart;
        }

        public void setAutoStart(boolean autoStart) {
            this.autoStart = autoStart;
        }

        public Integer getReconnect() {
            return reconnect;
        }

        public void setReconnect(Integer reconnect) {
            this.reconnect = reconnect;
        }

        public boolean isRetry() {
            return retry;
        }

        public void setRetry(boolean retry) {
            this.retry = retry;
        }

        public Class<? extends BootstrapStrategy<?, ?>> getBootstrapStrategy() {
            return bootstrapStrategy;
        }

        public void setBootstrapStrategy(Class<? extends BootstrapStrategy<?, ?>> bootstrapStrategy) {
            this.bootstrapStrategy = bootstrapStrategy;
        }

        @Override
        public String toString() {
            return "Configuration{" +
                    "localAddress=" + localAddress +
                    ", remoteAddress=" + remoteAddress +
                    ", name='" + name + '\'' +
                    ", protocol=" + protocol +
                    ", multicastAddress=" + multicastAddress +
                    ", broadcastAddress=" + broadcastAddress +
                    ", available=" + available +
                    ", autoStart=" + autoStart +
                    ", reconnect=" + reconnect +
                    ", retry=" + retry +
                    ", bootstrapStrategy=" + bootstrapStrategy +
                    '}';
        }
    }
}
